
#ifndef TOOLS_SERVER
#define TOOLS_SERVER

#include <cstdint>
#include <string>
#include <map>
#include <memory>
#include <functional>
#ifndef TOOLS_CONNECTION
#include "connection.h"
#endif
#ifndef TOOLS_DEFINE
#include "define.h"
#endif

class Loop;
class Channel;

struct ServerConfig
{
    int m_black_status{true};

};

class Server : public std::enable_shared_from_this<Server>
{
public:
    Server(Loop * loop);
    ~Server();
    bool ListenServer(int port);
    bool InitServerConfig(ServerConfig server_config);
    void OnConnectionCallback(OnConnection && func);
    void OnDisConnectionCallback(DisConnection && func);
    void OnMessageCallback(OnMessage && func);
    void DisConnFromConn(std::shared_ptr<Connection> conn);
    void MessageFromConn(std::shared_ptr<Connection> conn, std::shared_ptr<SocketBuffer> buffer);
private:
    void ReadAble(std::shared_ptr<Channel> channel, std::shared_ptr<TcpSocket> socket);
    void ErrorAble(std::shared_ptr<Channel> channel, std::shared_ptr<TcpSocket> socket);
private:
    Loop * m_loop;
    std::shared_ptr<Channel> m_channel;
    std::shared_ptr<TcpSocket> m_socket;
    OnConnection  m_onconn;
    DisConnection m_disconn;
    OnMessage     m_onmessage;
private:
    std::map<int64_t, std::shared_ptr<Connection>> m_connect_map;
    ServerConfig m_server_config;
};

#endif
